package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

import static com.sky.enumeration.OperationType.INSERT;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据查询条件进行查询
     * @param params
     * @return
     */
    List<ShoppingCart> queryByParmas(ShoppingCart params);

    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    @AutoFill(INSERT)
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) VALUES " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart cart);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    void saveBatch(List<ShoppingCart> shoppingCarts);

    /**
     * 删除购物车
     * @param id
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void remove(Long id);
}
